package com.clqteam.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.clqteam.service.SelectDailyReportService;
import com.clqteam.serviceimpl.SelectDailyReportServiceImpl;

import net.sf.json.JSONObject;

public class SelectDailyReportController extends HttpServlet {
    SelectDailyReportService seDaSerice=new SelectDailyReportServiceImpl();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	  req.setCharacterEncoding("utf8");
	  resp.setCharacterEncoding("utf8");
	  int page = Integer.parseInt(req.getParameter("page"));
		int rows = Integer.parseInt(req.getParameter("rows"));
		String time1=req.getParameter("date1");
		String time2=req.getParameter("date2");
		String emName=req.getParameter("emName");
		SimpleDateFormat sd=new SimpleDateFormat("YYYY-MM-dd HH:mm:ss");
		  Date date=new Date();
		  String time=sd.format(date);
		  if(("".equals(time1))||("".equals(time2))){
			   time1="2017-01-01 00:00:00";
			   time2=time;
		  }
		
		JSONObject  js = seDaSerice.findDailyReportInfo(page, rows, time1, time2, emName);
		PrintWriter  pw = resp.getWriter();
	     pw.write(js.toString());
	 
	}
}
